package com.kai.steering.data.service.entity.vo;

import com.kai.steering.data.service.entity.domainObject.KnowledgeDO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <pre>
 * 知识点 VO对象
 * </pre>
 *
 * @author kai
 * @date 2022-02-23
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ToString
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "KnowledgeVO对象", description = "知识点业务视图")
public class KnowledgeVO implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "知识点id")
    private String knowledgeId;
    @ApiModelProperty(value = "知识点名")
    private String knowledgeName;
    @ApiModelProperty(value = "知识点信息 ")
    private String knowledgeIntroduce;
    @ApiModelProperty(value = "创建时间")
    private Date creationDate;
    @ApiModelProperty(value = "管理员id或者用户id")
    private String founder;
    @ApiModelProperty(value = "上级知识点id")
    private String knowledgeSuperior;
    @ApiModelProperty(value = "级别")
    private Integer level;
    @ApiModelProperty(value = "下级知识点")
    private List<KnowledgeVO> childs;

    public KnowledgeVO(KnowledgeDO knowledgeDO) {
        this.convertKnowledgeVO(knowledgeDO);
    }
    public KnowledgeVO convertKnowledgeVO(KnowledgeDO knowledgeDO){
        this.knowledgeId=knowledgeDO.getKnowledgeId();
        this.knowledgeName=knowledgeDO.getKnowledgeName();
        this.knowledgeIntroduce=knowledgeDO.getKnowledgeIntroduce();
        this.creationDate=knowledgeDO.getCreationDate();
        this.founder=knowledgeDO.getFounder();
        this.knowledgeSuperior=knowledgeDO.getKnowledgeSuperior();
        this.level=knowledgeDO.getLevel();
        if (this.childs!=null) {
            this.childs =  knowledgeDO.getChilds().stream().map(knowledgeDO1 -> {
                return new KnowledgeVO(knowledgeDO1);
            }).collect(Collectors.toList());
        }

        return this;
    }
}